{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "635d8ebb",
   "metadata": {},
   "source": [
    "# Getting Started on Mac\n",
    "\n",
    "- Author: [JeongHo Shin](https://github.com/ThePurpleCollar)\n",
    "- Peer Review: [JeongGi Park](https://www.linkedin.com/in/jeonggipark/), [Wooseok Jeong](https://github.com/jeong-wooseok)\n",
    "- Proofread : [Q0211](https://github.com/Q0211)\n",
    "- This is a part of [LangChain Open Tutorial](https://github.com/LangChain-OpenTutorial/LangChain-OpenTutorial)\n",
    "\n",
    "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/LangChain-OpenTutorial/LangChain-OpenTutorial/blob/main/01-Basic/02-Getting-Started-Mac.ipynb)[![Open in GitHub](https://img.shields.io/badge/Open%20in%20GitHub-181717?style=flat-square&logo=github&logoColor=white)](https://github.com/LangChain-OpenTutorial/LangChain-OpenTutorial/blob/main/01-Basic/02-Getting-Started-Mac.ipynb)\n",
    "## Overview\n",
    "\n",
    "This guide provides a comprehensive setup process tailored for developing with LangChain on a Mac. LangChain is a framework for building applications powered by large language models (LLMs), and this guide ensures your environment is fully optimized for seamless integration and development.\n",
    "\n",
    "# Table of Contents\n",
    "\n",
    "- [Overview](#overview)\n",
    "- [Opening Terminal](#opening-terminal)\n",
    "- [Installing Homebrew](#installing-homebrew)\n",
    "- [Verifying Xcode Installation](#verifying-xcode-installation)\n",
    "- [Downloading Practice Code](#downloading-practice-code)\n",
    "- [Python and Environment Configuration](#python-and-environment-configuration)\n",
    "- [Development Tools Setup](#development-tools-setup)\n",
    "\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a630f46",
   "metadata": {},
   "source": [
    "## Opening Terminal\n",
    "- Open Spotlight Search by pressing **Command + Space** .\n",
    "\n",
    "- Search for **terminal** and press Enter to open the Terminal."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edd88e38",
   "metadata": {},
   "source": [
    "## Installing Homebrew\n",
    "\n",
    "### Running the Homebrew Installation Command\n",
    "- Run the following command in the Terminal to install Homebrew:\n",
    "   ```bash\n",
    "   /bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"\n",
    "   ```\n",
    "\n",
    "- Enter your account password when prompted.\n",
    "![PasswordZ](assets/01-Follow-the-Installation-Video_Mac-01.png)\n",
    "     \n",
    "- Press ENTER to proceed with the installation."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "913b58a6",
   "metadata": {},
   "source": [
    "### Configuring Homebrew Environment\n",
    "\n",
    "- Run the following command to check your username:\n",
    "   ```bash\n",
    "   \n",
    "   whoami\n",
    "   ```\n",
    "![Jupyter Extension](assets/01-Follow-the-Installation-Video_Mac-02.png)\n",
    "\n",
    "- Check the installation path of Homebrew:\n",
    "   ```bash\n",
    "\n",
    "   which brew\n",
    "   ```\n",
    "\n",
    "- Verify the installation path of Homebrew:\n",
    "   - **Case 1** : If the output is **/opt/homebrew/bin/brew** , use the following command to configure the environment:\n",
    "      ```bash\n",
    "      echo 'eval \"$(/opt/homebrew/bin/brew shellenv)\"' >> /Users/<your-username>/.zprofile\n",
    "      ```\n",
    "\n",
    "   - **Case 2** : If the output is **/usr/local/bin/brew** , use the following command:\n",
    "      ```bash\n",
    "      echo 'eval \"$(/usr/local/bin/brew shellenv)\"' >> /Users/<your-username>/.zprofile\n",
    "      ```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05b6427c",
   "metadata": {},
   "source": [
    "## Verifying Xcode Installation\n",
    "\n",
    "To check if Xcode Command Line Tools are installed, run the following command in your terminal:\n",
    "\n",
    "```bash\n",
    "xcode-select --install\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "070b418b",
   "metadata": {},
   "source": [
    "## Downloading Practice Code\n",
    "\n",
    "[Reference] Practice code repository: [LangChain Practice Code](https://github.com/LangChain-OpenTutorial/LangChain-OpenTutorial)\n",
    "\n",
    "\n",
    "### Verifying Git Installation\n",
    "\n",
    "- Check if Git is installed by running the following command in your terminal:\n",
    "   ```bash\n",
    "   git --version\n",
    "   ```\n",
    "\n",
    "- If the command outputs the Git version, you already have Git installed, and no further action is required.\n",
    "\n",
    "- If Git is not installed, you can install it using Homebrew:\n",
    "   ```bash\n",
    "   brew install git\n",
    "   ```\n",
    "\n",
    "- After installation, verify Git again:\n",
    "   ```bash\n",
    "   git --version\n",
    "   ```\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c41318e",
   "metadata": {},
   "source": [
    "### Downloading Practice Code with Git\n",
    "- Navigate to the **Documents** folder (or any other folder where you want to download the practice code). Use the following command:\n",
    "   ```bash\n",
    "   cd Documents\n",
    "   ```\n",
    "- If you want to use a different directory, replace Documents with your desired path.\n",
    "\n",
    "- Use the **git** command to download the practice code from the repository. Run the following command in your terminal:\n",
    "   ```bash\n",
    "   git clone https://github.com/LangChain-OpenTutorial/LangChain-OpenTutorial.git\n",
    "   ```\n",
    "![](assets/01-Follow-the-Installation-Video_Mac-03.png)\n",
    "\n",
    "- The repository will be cloned into a folder named LangChain-OpenTutorial within the selected directory.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9df2082",
   "metadata": {},
   "source": [
    "## Installing Pyenv\n",
    "\n",
    "#### Reference\n",
    "For detailed documentation, refer to the [Pyenv GitHub Page](https://github.com/pyenv/pyenv?tab=readme-ov-file#understanding-python-version-selection).\n",
    "\n",
    "---\n",
    "\n",
    "#### Steps to Install Pyenv\n",
    "\n",
    "1. Update Homebrew and install ```pyenv``` using the following commands:\n",
    "   ```bash\n",
    "   brew update\n",
    "   brew install pyenv\n",
    "   ```\n",
    "\n",
    "2. Add the following lines to your ~/.zshrc file. Copy and paste the commands into your terminal:\n",
    "   ```bash\n",
    "   echo 'export PYENV_ROOT=\"$HOME/.pyenv\"' >> ~/.zshrc\n",
    "   echo '[[ -d $PYENV_ROOT/bin ]] && export PATH=\"$PYENV_ROOT/bin:$PATH\"' >> ~/.zshrc\n",
    "   echo 'eval \"$(pyenv init -)\"' >> ~/.zshrc\n",
    "   ```\n",
    "\n",
    "3. If you encounter a permissions error, resolve it by running these commands:\n",
    "   ```bash\n",
    "   sudo chown $USER ~/.zshrc\n",
    "   echo 'export PYENV_ROOT=\"$HOME/.pyenv\"' >> ~/.zshrc\n",
    "   echo '[[ -d $PYENV_ROOT/bin ]] && export PATH=\"$PYENV_ROOT/bin:$PATH\"' >> ~/.zshrc\n",
    "   echo 'eval \"$(pyenv init -)\"' >> ~/.zshrc\n",
    "   ```\n",
    "\n",
    "4. Restart the terminal shell to apply the changes:\n",
    "   ```bash\n",
    "   exec \"$SHELL\"\n",
    "   ```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25f630fc",
   "metadata": {},
   "source": [
    "## Installing Python\n",
    "\n",
    "- Use ```pyenv``` to install Python 3.11:\n",
    "   ```bash\n",
    "   pyenv install 3.11\n",
    "   ```\n",
    "\n",
    "- Set Python 3.11 as the global Python version:\n",
    "    ```bash\n",
    "    pyenv global 3.11\n",
    "    ```\n",
    "\n",
    "- Restart the shell to ensure the changes take effect:\n",
    "    ```bash\n",
    "    exec zsh\n",
    "    ```\n",
    "\n",
    "- Verify the installed Python version:\n",
    "    ```bash\n",
    "    python --version\n",
    "    ```\n",
    "\n",
    "- Ensure the output shows 3.11."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ad5c336",
   "metadata": {},
   "source": [
    "## Installing Poetry\n",
    "\n",
    "#### Reference\n",
    "For detailed documentation, refer to the [Poetry Official Documentation](https://python-poetry.org/docs/#installing-with-the-official-installer).\n",
    "\n",
    "---\n",
    "\n",
    "#### Steps to Install and Configure Poetry\n",
    "\n",
    "- Install Poetry using ```pip3```:\n",
    "   ```bash\n",
    "   pip3 install poetry\n",
    "   ```\n",
    "\n",
    "- Set up a Python virtual environment using Poetry:\n",
    "   ```bash\n",
    "    poetry shell\n",
    "    ```\n",
    "\n",
    "- Update all Python dependencies in the project:\n",
    "   ```bash\n",
    "    poetry update\n",
    "    ```\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d539f569",
   "metadata": {},
   "source": [
    "## Installing Visual Studio Code\n",
    "\n",
    "- **Download Visual Studio Code**:\n",
    "   - Visit the [Visual Studio Code Download Page](https://code.visualstudio.com/download).\n",
    "   - Download the installer for your operating system.\n",
    "\n",
    "- **Install Visual Studio Code**:\n",
    "   - Follow the installation instructions for your system.\n",
    "   - Dag the application to the **Applications** folder.\n",
    "\n",
    "- **Install Extensions**:\n",
    "   - Open Visual Studio Code.\n",
    "   - Click on the **Extensions** icon on the left sidebar.\n",
    "![Extensions Icon](assets/01-Follow-the-Installation-Video_Mac-04.png)\n",
    "\n",
    "   - Search for **\"python\"** in the Extensions Marketplace and install it.\n",
    "![Python Extension](assets/01-Follow-the-Installation-Video_Mac-05.png)\n",
    "\n",
    "   - Search for **\"jupyter\"** in the Extensions Marketplace and install it.\n",
    "![Jupyter Extension](assets/01-Follow-the-Installation-Video_Mac-06.png)\n",
    "\n",
    "- **Restart Visual Studio Code**:\n",
    "   - After installing the extensions, restart Visual Studio Code to apply the changes.\n",
    "\n",
    "- **Select Python Environment**:\n",
    "   - Click on **\"Select Kernel\"** in the top-right corner of Visual Studio Code.\n",
    "   - Choose the Python virtual environment you set up earlier.\n",
    "\n",
    "   - **Note**: If your environment does not appear in the list, restart Visual Studio Code.\n",
    "\n",
    "---\n",
    "\n",
    "Now, Visual Studio Code is fully set up and ready for development with Python and Jupyter support.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18d43df5",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "langchain-opentutorial-i-KKkGhc-py3.11",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
